package vip.xiaonuo.supplier.modular.custom.custom.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.custom.custom.entity.SupplierCustom;
import vip.xiaonuo.supplier.modular.custom.custom.param.SupplierCustomAddParam;
import vip.xiaonuo.supplier.modular.custom.custom.param.SupplierCustomEditParam;
import vip.xiaonuo.supplier.modular.custom.custom.param.SupplierCustomIdParam;
import vip.xiaonuo.supplier.modular.custom.custom.param.SupplierCustomPageParam;
import vip.xiaonuo.supplier.modular.custom.custom.service.SupplierCustomService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 客户信息控制器
 *
 * @author Mr.wu
 * @date  2025/03/17 11:20
 */
@Tag(name = "客户信息控制器")
@RestController
@Validated
public class SupplierCustomController {

    @Resource
    private SupplierCustomService supplierCustomService;

    /**
     * 获取客户信息分页
     *
     * @author Mr.wu
     * @date  2025/03/17 11:20
     */
    @Operation(summary = "获取客户信息分页")
    @SaCheckPermission("/supplier/custom/custom/page")
    @GetMapping("/supplier/custom/custom/page")
    public CommonResult<Page<SupplierCustom>> page(SupplierCustomPageParam supplierCustomPageParam) {
        return CommonResult.data(supplierCustomService.page(supplierCustomPageParam));
    }

    /**
     * 添加客户信息
     *
     * @author Mr.wu
     * @date  2025/03/17 11:20
     */
    @Operation(summary = "添加客户信息")
    @CommonLog("添加客户信息")
    @SaCheckPermission("/supplier/custom/custom/add")
    @PostMapping("/supplier/custom/custom/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierCustomAddParam supplierCustomAddParam) {
        supplierCustomService.add(supplierCustomAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑客户信息
     *
     * @author Mr.wu
     * @date  2025/03/17 11:20
     */
    @Operation(summary = "编辑客户信息")
    @CommonLog("编辑客户信息")
    @SaCheckPermission("/supplier/custom/custom/edit")
    @PostMapping("/supplier/custom/custom/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierCustomEditParam supplierCustomEditParam) {
        supplierCustomService.edit(supplierCustomEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除客户信息
     *
     * @author Mr.wu
     * @date  2025/03/17 11:20
     */
    @Operation(summary = "删除客户信息")
    @CommonLog("删除客户信息")
    @SaCheckPermission("/supplier/custom/custom/delete")
    @PostMapping("/supplier/custom/custom/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierCustomIdParam> supplierCustomIdParamList) {
        supplierCustomService.delete(supplierCustomIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取客户信息详情
     *
     * @author Mr.wu
     * @date  2025/03/17 11:20
     */
    @Operation(summary = "获取客户信息详情")
    @SaCheckPermission("/supplier/custom/custom/detail")
    @GetMapping("/supplier/custom/custom/detail")
    public CommonResult<SupplierCustom> detail(@Valid SupplierCustomIdParam supplierCustomIdParam) {
        return CommonResult.data(supplierCustomService.detail(supplierCustomIdParam));
    }
}
